@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
           产品分类列表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/product/productCategory/add" class="btn btn-primary">添加产品分类</a>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Product</a></li>
            <li class="active">Product_Category</li>
        </ol>
        <div class="input-group margin">
            <form action="/proCategory" method="get">
                <select style="width: 150px" id="sel"  name="type" class="form-control" onchange="select()">
                    @foreach($navigation as $value)
                        <option value="{{ $value['id'] }}" @if($value['id'] == $type)selected="selected"@endif>{{ $value['navigation'] }}</option>
                    @endforeach
                </select>

                <div style="float: left" id="form">
                    <input id="datepicker" style="width: 200px"  name="param" type="text" class="form-control" value="{{$param}}">
                </div>
                <input  type="submit" class="btn btn-info btn-flat" value="Go!">
            </form>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="example2" class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                @foreach($navigation as $nav)
                                    <th>{{$nav['navigation']}}</th>
                                @endforeach
                                <th>图标</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($cate as $c)
                                <tr>
                                    <td>{{ $c['id'] }}</td>
                                    <td>{{ $c['rank'] }}</td>
                                    <td>{{ $c['update_time'] }}</td>
                                    <td>{{ $c['name'] }}</td>
                                    <td>
                                        @if($c['parent_id'] == 0)无
                                        @else{{ App\Model\ProductCategory::find($c['parent_id'])['name'] }}
                                        @endif
                                    </td>
                                    <td>
                                        @if($c['level'] == 1)
                                            一级分类
                                        @elseif($c['level'] == 2)
                                            二级分类
                                        @endif
                                    </td>
                                    <td>
                                        @if($c['status'] == 0)
                                            <label class="btn btn-warning btn-xs">禁用</label>
                                        @else
                                            <label class="btn btn-success btn-xs">启用</label>
                                        @endif
                                    </td>
                                    <td><img width="50px" height="50px" src="http://vipyipoint.oss-cn-beijing.aliyuncs.com/{{ $c['picture'] }}"/> </td>
                                    <td>
                                        <a class="btn btn-primary btn-xs"  href="{{ url('productCategory/update/'.$c['id'].'/'.$c['level']) }}">修改<a>
                                        {{--<a class="btn btn-danger btn-xs" href="javascript:delCate({{ $c['id'] }})">删除<a>--}}
                                        @if($c['status'] == 0)
                                            <a id="setDisabled" class="btn btn-success btn-xs" href="javascript:disabled('{{ $c['id'] }}',1)">启用<a>
                                        @elseif($c['status'] == 1)
                                            <a id="setDisabled" class="btn btn-warning btn-xs" href="javascript:disabled('{{ $c['id'] }}',0)">禁用<a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div style="text-align: center;">
                        {!! $cate->appends(['type'=>$type,'param'=>$param,'count'=>$count])->links() !!}
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>
        //删除
//        function delCate(id) {
//            layer.confirm('删除后不可恢复，是否继续?', {
//                btn:['确定','取消']
//            },function() {
//                $.ajax({
//                    url: 'delCate/'+id,
//                    type: "GET",
//                    data: id,
//                    dataType: "json",
//                    success: function(res) {
//                        console.log(res);
//                        if(res.code == 100) {
//                            window.location.href = "index";
//                            layer.msg(res.msg)
//                        }
//                        else {
//                            layer.msg(res.msg)
//                        }
//                    }
//                });
//            },function() {
//
//            });
//        }
        //禁用
        function disabled(id,status) {
            $.ajax({
                url: '/disabled',
                type: "GET",
                data:{id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        if($('#setDisabled').html() == '禁用'){
                            $('#setDisabled').addClass('btn btn-success btn-xs');
                        }else{
                            $('#setDisabled').addClass('btn btn-danger btn-xs');
                        }
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5})
                    }
                }
            });
        }
    </script>
@stop
